﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Itfort;

namespace WanPiJie.WebSite.MyBaby
{
	public partial class EditBabyInfo_f : PageMustLogin_BabyId
	{
		protected void Page_Load(object sender, EventArgs e)
		{

		}

		protected override void HttpGetProcess()
		{
			this.f_Name.Text = this.Baby.Name;
			// 提取宝宝出生信息
			GrowthRecord birthInfo = WpjSf.GrowthRecordService.GetBirthGrowthRecord(this.Baby);
			if (birthInfo != null)
			{
				this.f_Height.Text = birthInfo.Height.ToString();
				this.f_Weight.Text = birthInfo.Weight.ToString();
				this.f_HeadSize.Text = birthInfo.HeadSize.ToString();
				this.f_ChestSize.Text = birthInfo.ChestSize.ToString();
			}
		}

		protected void BtnOK_Click(object sender, EventArgs e)
		{
			string name = this.f_Name.Text;
			GrowthRecord birthInfo = WpjSf.GrowthRecordService.GetBirthGrowthRecord(this.Baby);
			if (birthInfo != null)
			{
				MyConvert.SetObject<GrowthRecord>(Request.Form, "f_", birthInfo);
				WpjSf.GrowthRecordService.UpdateGrowthRecord(this.Baby.Id, this.Baby.Birthday,
					birthInfo.Height, birthInfo.Weight, birthInfo.HeadSize, birthInfo.ChestSize);
			}
			else
			{
				birthInfo = MyConvert.ToObject<GrowthRecord>(Request.Form, "f_");

				WpjSf.GrowthRecordService.AddGrowthRecord(this.Baby.Id, this.Baby.Birthday,
					birthInfo.Height, birthInfo.Weight, birthInfo.HeadSize, birthInfo.ChestSize);
			}
			WpjSf.BabyService.UpdateName(this.Baby.Id, name);
		}
	}
}